package com.newtouch.bxzs.database.synchronize.batch.job;

import com.newtouch.bxzs.database.synchronize.batch.step.LocalDataStep;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 本地跑批job
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/3/2 17:13</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class BatchUpdateJob {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private LocalDataStep localDataStep;

    /**
     * 广告发布与撤销
     * @return Job
     */
    public Job advertisementJob(){
        return jobBuilderFactory.get("advertisementJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.revokeAdvertisement())
                .next(localDataStep.publishAdvertisement())
                .build();
    }

    /**
     * 产品的发布与撤销
     * @return Job
     */
    public Job productJob(){
        return jobBuilderFactory.get("productJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateProductStatus())
                .build();
    }

    /**
     * 通知的发布与撤销
     * @return Job
     */
    public Job notificationJob(){
        return jobBuilderFactory.get("notificationJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateNotificationStatus())
                .build();
    }

    /**
     * 知识小灵通的发布与撤销
     * @return Job
     */
    public Job knowledgeCardJob(){
        return jobBuilderFactory.get("knowledgeCardJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateKnowledgeCardStatus())
                .build();
    }

    /**
     * 知识库的发布与撤销
     * @return Job
     */
    public Job knowledgeBaseJob(){
        return jobBuilderFactory.get("knowledgeBaseJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateKnowledgeBaseStatus())
                .build();
    }

    /**
     * 提醒升级
     * @return Job
     */
    public Job remindToUpgradeJob(){
        return jobBuilderFactory.get("remindToUpgradeJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.remindToUpgrade())
                .build();
    }

    /**
     * 结束营销活动
     * @return Job
     */
    public Job finishMarketingActivityJob(){
        return jobBuilderFactory.get("finishMarketingActivityJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.finishMarketingActivity())
                .build();
    }

    /**
     * 结束营销活会议
     * @return Job
     */
    public Job finishMarketingConferenceJob(){
        return jobBuilderFactory.get("finishMarketingConferenceJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.finishMarketingConference())
                .build();
    }

    /**
     * 课程的发布与撤销
     * @return Job
     */
    public Job updateCourseStatusJob(){
        return jobBuilderFactory.get("updateCourseStatusJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateCourseStatus())
                .build();
    }

    /**
     * 考试的发布与撤销
     * @return Job
     */
    public Job updateExaminationStatusJob(){
        return jobBuilderFactory.get("updateExaminationStatusJob")
                .incrementer(new RunIdIncrementer())
                .start(localDataStep.updateExaminationStatus())
                .build();
    }
}
